package org.mtmi.ui.controls;

import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Transform;

/**
 * Store a snapshot of a GC state, an can replace GC is captured state.
 * 
 * @author arnaud
 */
public class GCSave 
{
	private Font oldFont;
	private Color oldBG;
	private Color oldFG;
	private int antialias;
	private int textAntialias;
	private Transform transform;
	
	public GCSave( GC gc ) {
		saveGC( gc );
	}
	
	public void saveGC(GC gc) {
		oldFont = gc.getFont();
		oldBG = gc.getBackground();
		oldFG = gc.getForeground();
		antialias = gc.getAntialias();
		textAntialias = gc.getTextAntialias();
		if( transform==null ) transform = new Transform( gc.getDevice() );
		gc.getTransform(transform);
	}
	
	public void restoreGC(GC gc) {
		gc.setForeground(oldFG);
		gc.setBackground(oldBG);
		gc.setFont(oldFont);
		gc.setAntialias(antialias);
		gc.setTextAntialias(textAntialias);
		gc.setTransform(transform);
	}
}
